package com.service;

import com.dao.BookCollectionDao;
import com.dto.BookCollectionDTO;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.util.RestException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

/**
 * @author linyukun
 * @date 2022/8/8 18:39
 */
@Service
public class BookCollectionServiceImpl {

    @Autowired
    private BookCollectionDao bookCollectionDao;

    public Object addBookCollection(BookCollectionDTO dto) {
        if(ObjectUtils.isEmpty(dto.getBookId())){
           throw new RestException("请传递bookId");
        }
        return bookCollectionDao.addBookCollection(dto);
    }

    public Object getBookCollectionList(BookCollectionDTO dto) {
        PageHelper.startPage(dto.getPageNum(), dto.getPageSize());
        return new PageInfo(bookCollectionDao.getBookCollectionList(dto));
    }

    public Object delBookCollectionById(BookCollectionDTO dto) {
        return bookCollectionDao.delBookCollectionById(dto);
    }
}
